package com.rockcent.mall.controller;

import com.rockcent.common.common.JsonResult;
import com.rockcent.common.common.PageResult;
import com.rockcent.common.common.RestDoing;
import com.rockcent.common.controller.BaseController;
import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.common.utils.RDateFormatUtils;
import com.rockcent.common.utils.RDateUtils;
import com.rockcent.mall.Routes;
import com.rockcent.mall.helper.GiftPacketHelper;
import com.rockcent.mall.lib.domain.*;
import com.rockcent.mall.lib.domain.enumclass.GiftPacketProductType;
import com.rockcent.mall.lib.domain.enumclass.GiftPacketStatus;
import com.rockcent.mall.lib.domain.enumclass.MarketMerchantCooperationStatus;
import com.rockcent.mall.lib.domain.enumclass.MarketMerchantProductSalesStatus;
import com.rockcent.mall.lib.dto.GiftPacketDto;
import com.rockcent.mall.lib.dto.MerchantGiftPacketCouponDto;
import com.rockcent.mall.lib.dto.MerchantGiftPacketProductDto;
import com.rockcent.mall.lib.dto.UserInfoDto;
import com.rockcent.mall.lib.helper.BaseUserHelper;
import com.rockcent.mall.lib.repository.MarketMerchantCooperationRepository;
import com.rockcent.mall.lib.repository.MarketMerchantGiftPacketSalesRepository;
import com.rockcent.mall.lib.repository.MerchantGiftPacketRepository;
import com.rockcent.mall.lib.repository.MerchantProductRepository;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by DK on 16/10/17.
 */
@RestController
public class MarketMerchantGIftPacketController extends BaseController {
    private final Logger log = LoggerFactory.getLogger(MarketMerchantGIftPacketController.class);

    @Autowired
    private BaseUserHelper userHelper;

    @Autowired
    private GiftPacketHelper giftPacketHelper;

    @Autowired
    private MerchantGiftPacketRepository merchantGiftPacketRepository;

    @Autowired
    private MarketMerchantGiftPacketSalesRepository marketMerchantGiftPacketSalesRepository;

    @Autowired
    private MerchantProductRepository merchantProductRepository;

    @Autowired
    private MarketMerchantCooperationRepository marketMerchantCooperationRepository;

    /**
     * @api {get} /market/merchant/gift/packet/page 产品礼包 礼包市场 分页
     * @apiGroup GIFT_PACKET
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {String=NO("不显示"), 为空("显示")} showSaleGiftPacket 不显示我共享的礼包
     * @apiParam {String=ASC("升序"), DESC("降序")} sort 排序(sortByName为空则sort为空,sortByName传值则sort传值)
     * @apiParam {String=date_created("发布时间") resell_fee("佣金") sell_price("售价")} sortByName 按字段排序
     * @apiParam {String} keyword 产品编号/名称/商家名称
     *
     * @apiSuccess {Long} id 礼包ID
     * @apiSuccess {String} name 礼包名称
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Date} dateEnabled 礼包开始时间
     * @apiSuccess {Date} dateDisabled 礼包结束时间
     * @apiSuccess {Long} marketPacketId 分销礼包唯一的识别码
     * @apiSuccess {String} coverUrl 广告封面
     * @apiSuccess {String} intro 礼包介绍
     * @apiSuccess {BigDecimal} shareFee 分享返利
     * @apiSuccess {BigDecimal} basePrice 总价
     * @apiSuccess {BigDecimal} sellPrice 礼包价
     * @apiSuccess {Boolean} isRecommend 是否共享营销
     * @apiSuccess {Long} merchantId 商家ID
     * @apiSuccess {Long} mallId 商城ID
     * @apiSuccess {String} merchantName 商家名称
     * @apiSuccess {BigDecimal} resellFee 分销佣金
     * @apiSuccess {BigDecimal} isSale 为空表示没有销售过
     * @apiSuccess {String=S2_SELLING("已上架"), S3_UNLOAD("已下架"), S4_SOLDOUT("已售完"), S5_FINISHED("已结束"), S6_UNSTART("未开始")} status 礼包状态
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *     "code" : "1".
     *     "desc" : "成功",
     *     "data" : [
     *            {
     *                "id" : 23,
     *                "name" : "组合礼包",
     *                "dateCreated" : "2016-07-22 10:49:28",
     *                "lastUpdated" : "2016-07-22 10:49:28",
     *                "dateEnabled" : "2016-07-22 10:49:28",
     *                "dateDisabled" : "2016-07-22 10:49:28",
     *                "marketPacketId" : 343,
     *                "coverUrl" : "/20160601/201606011413084VOvLKgN.jpg",
     *                "intro" : "礼包介绍",
     *                "shareFee" : 21,
     *                "basePrice" : 231,
     *                "sellPrice" : 222,
     *                "isRecommend" : true,
     *                "merchantId" : 2,
     *                "mallId" : 1,
     *                "isSale" : 234,
     *                "merchantName" : "萨瓦迪卡",
     *                "status" : "S2_SELLING",
     *                "resellFee" : "23"
     *            },
     *            .......
     *     ]
     * }
     */
    @RequestMapping(value = Routes.MARKET_MERCHANT_GIFT_PACKET_PAGE, method = RequestMethod.GET)
    public JsonResult marketGiftPacketPage(HttpServletRequest request, GiftPacketDto giftPacketDto){
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            PageResult<GiftPacketDto> pageResult = merchantGiftPacketRepository.findMarketGiftPacketPage(giftPacketDto.getSort(), giftPacketDto.getSortByName(), giftPacketDto.getKeyword(), giftPacketDto.getShowSaleGiftPacket(), userInfoDto.mall.getId(), userInfoDto.merchant.getId(), this.getPage(giftPacketDto.getPageNo(), giftPacketDto.getPageSize()));
            pageResult.data.stream().map(giftPacket ->{
                try {
                    giftPacket.setDateDisabled(RDateUtils.parseDate(RDateFormatUtils.formatParseDatePattern(giftPacket.getDateDisabled())));
                    giftPacket.setDateEnabled(RDateUtils.parseDate(RDateFormatUtils.formatParseDatePattern(giftPacket.getDateEnabled())));
                } catch (ParseException e) {
                    log.error(e.getMessage(),e);
                }
                return giftPacket;
            }).collect(Collectors.toList());
            pageResult.setUrl(Routes.MARKET_MERCHANT_GIFT_PACKET_PAGE);
            jsonResult.data = pageResult;
        };
       return doing.go(request, log);
    }

    /**
     * @api {put} /market/merchant/gift/packet/sale 产品礼包 礼包市场 我要销售
     * @apiGroup GIFT_PACKET
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {Long} id <code>必传参数</code> 礼包id
     *
     * @apiSuccess {String=1("成功"), 10("商家没有合作关系")} code 返回码
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     *      "code": "1",
     *      "desc": "成功"
     * }
     *
     */
    @Transactional
    @RequestMapping(value = Routes.MARKET_MERCHANT_GIFT_PACKET_SALE, method = RequestMethod.PUT)
    public JsonResult marketGiftPacketSale(HttpServletRequest request, @RequestBody GiftPacketDto giftPacketDto){
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            if (giftPacketDto.getId() == null) {
                jsonResult.remind(MerchantGiftPacket.CHECK_ID_IS_NOT_NULL,log);;
                return;
            }
            MerchantGiftPacket giftPacket = merchantGiftPacketRepository.findOne(giftPacketDto.getId());
            if (giftPacket == null) {
                jsonResult.remind(MerchantGiftPacket.REMIND_RECORD_IS_NOT_EXIST,log);;
                return;
            }
            if (GiftPacketStatus.S5_FINISHED == giftPacket.getStatus()) {
                jsonResult.remind(MerchantGiftPacket.GIFT_PACKET_FINISHED,log);
                return;
            }
            if (GiftPacketStatus.S3_UNLOAD == giftPacket.getStatus()) {
                jsonResult.remind(MerchantGiftPacket.GIFT_PACKET_UNLOAD,log);
                return;
            }
            if (GiftPacketStatus.S1_DRAFTED == giftPacket.getStatus()) {
                jsonResult.remind(MerchantGiftPacket.GIFT_PACKET_DRAFTED,log);
                return;
            }
            if (GiftPacketStatus.S4_SOLDOUT == giftPacket.getStatus()) {
                jsonResult.remind(MerchantGiftPacket.GIFT_PACKET_SOLDOUT,log);
                return;
            }
            if (giftPacket.getMerchantId() == userInfoDto.merchant.getId()) {
                jsonResult.remind(MerchantGiftPacket.GIFT_PACKET_SELF,log);
                return;
            }
            //保存分销产品礼包到商家中
           /* MerchantGiftPacket merchantGiftPacket = new MerchantGiftPacket();
            RBeanUtils.copyProperties(giftPacket, merchantGiftPacket, new String[]{"id"});
            merchantGiftPacket.setMallId(userInfoDto.mall.getId());
            merchantGiftPacket.setMerchantName(userInfoDto.merchant.getName());
            merchantGiftPacket.setMerchantId(userInfoDto.merchant.getId());
            merchantGiftPacket.setProductMarketId(giftPacket.getId());
            merchantGiftPacketRepository.save(merchantGiftPacket);*/

            //分销关系表 插入一条记录
            MarketMerchantGiftPacketSales merchantGiftPacketSales = new MarketMerchantGiftPacketSales();
            merchantGiftPacketSales.setPacketId(giftPacket.getId());
            merchantGiftPacketSales.setDistributorMallId(userInfoDto.mall.getId());
            merchantGiftPacketSales.setDistributorMerchantId(userInfoDto.merchant.getId());
            merchantGiftPacketSales.setDistributorStatus(MarketMerchantProductSalesStatus.REFUSE);
            merchantGiftPacketSales.setSupplierMallId(giftPacket.getMallId());
            merchantGiftPacketSales.setSupplierMerchantId(giftPacket.getMerchantId());
            merchantGiftPacketSales.setSupplierStatus(MarketMerchantProductSalesStatus.REFUSE);
            merchantGiftPacketSales.setIsDelete(Whether.YES);
            marketMerchantGiftPacketSalesRepository.save(merchantGiftPacketSales);
        };
        return doing.go(request, log);
    }

    /**
     * @api {post} /market/merchant/gift/packet/sale_save 产品礼包 礼包市场 我要销售 保存
     * @apiGroup GIFT_PACKET
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {Long} id <code>必须参数</code> 礼包ID
     * @apiParam {String} name <code>必须参数</code> 礼包标题
     * @apiParam {String} coverUrl <code>必须参数</code> 礼包广告图
     * @apiParam {Long} masterPacketProduct_productId <code>必须参数</code> 礼包主产品ID
     * @apiParam {BigDecimal} masterPacketProduct_packetPrice <code>必须参数</code> 礼包主产品单价
     * @apiParam {Long} masterPacketProduct_useNumber <code>必须参数</code> 礼包主产品使用数量
     * @apiParam {Long} masterPacketProduct_merchantId <code>必须参数</code> 礼包主产品商家ID
     * @apiParam {Date} dateEnabled <code>必须参数</code> 礼包开始时间
     * @apiParam {Date} dateDisabled <code>必须参数</code> 礼包结束时间
     * @apiParam {BigDecimal} basePrice <code>必须参数</code> 总价
     * @apiParam {BigDecimal} sellPrice <code>必须参数</code> 礼包价
     * @apiParam {String} intro 礼包介绍
     * @apiParam {Long} collocationPacketProductList_productId 搭配产品ID
     * @apiParam {BigDecimal} collocationPacketProductList_packetPrice 搭配产品单价
     * @apiParam {Long} collocationPacketProductList_useNumber 搭配产品使用数量
     * @apiParam {Long} collocationPacketProductList_merchantId 搭配产品商家ID
     * @apiParam {Long} merchantPacketCouponList_couponId 卡卷ID
     * @apiParam {Long} merchantPacketCouponList_useNumber 卡卷使用数量
     * @apiParam {Long} merchantPacketCouponList_merchantId 卡卷商家ID
     * @apiParam {String} shareFee 分享返利
     * @apiParam {String} recommend <code>必须参数</code>  传false
     *
     * @apiSuccessExample {json} Response
     * {
     *     "code" : "1".
     *     "desc" : "成功"
     * }
     *
     */
    @Transactional
    @RequestMapping(value = Routes.MARKET_MERCHANT_GIFT_PACKET_SALE_SAVE, method = RequestMethod.POST)
    public JsonResult marketGiftPacketSaleSave(HttpServletRequest request, @RequestBody  GiftPacketDto giftPacketDto){
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {

            if (giftPacketDto.getId() == null) {
                jsonResult.remind(MerchantGiftPacket.CHECK_ID_IS_NOT_NULL,log);;
                    return;
            }

            if (StringUtils.isNotBlank(giftPacketDto.getStatus()) && !EnumUtils.isValidEnum(GiftPacketStatus.class, giftPacketDto.getStatus())) {
                jsonResult.remind("礼包状态 S1_DRAFTED(\"草稿\"), S2_SELLING(\"发布\")", log);
                return;
            }
            if (StringUtils.isBlank(giftPacketDto.getName())) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_NAME_IS_NOT_NULL, log);
                return;
            }
            if (StringUtils.isBlank(giftPacketDto.getCoverUrl())) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_COVER_URL_IS_NOT_NULL, log);
                return;
            }
            if (giftPacketDto.getDateEnabled() == null) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_DATE_ENABLE_IS_NOT_NULL, log);
                return;
            }
            if (giftPacketDto.getDateDisabled() == null) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_DATE_DISABLE_IS_NOT_NULL, log);
                return;
            }
            if (giftPacketDto.getMasterPacketProduct() == null) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_MASTER_PRODUCT_IS_NOT_NULL, log);
                return;
            }
            if (giftPacketDto.getBasePrice() == null) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_BASE_PRICE_IS_NOT_NULL, log);
                return;
            }
            if (giftPacketDto.getSellPrice() == null) {
                jsonResult.errorParam(MerchantGiftPacket.CHECK_SELL_PRICE_IS_NOT_NULL, log);
                return;
            }

            MerchantGiftPacket merchantGiftPacket = merchantGiftPacketRepository.findByIdAndMerchantIdAndMarketIdIsNull(giftPacketDto.getId(), giftPacketDto.getMerchantId());

            if (merchantGiftPacket == null) {
                jsonResult.remind(MerchantGiftPacket.REMIND_RECORD_IS_NOT_EXIST,log);;
                return;
            }

            Product masterProduct = merchantProductRepository.findOne(giftPacketDto.getMasterPacketProduct().getProductId());
            if (masterProduct == null) {
                jsonResult.remind("您好,您所选的主产品不存在",log);
                return;
            }

            MarketMerchantGiftPacketSales packetSales = marketMerchantGiftPacketSalesRepository.findByPacketIdAndDistributorMerchantIdAndDistributorMallIdAndIsDeleteAndDistributorStatus(giftPacketDto.getId(), giftPacketDto.getMerchantId(), giftPacketDto.getMallId(), Whether.NO, MarketMerchantProductSalesStatus.PASS);
            if (packetSales != null) {
                jsonResult.remind("你已经销售过此礼包!",log);
                return;
            }

            Map<Long, String> mapCoupon = giftPacketHelper.checkCoupon(giftPacketDto.getMerchantPacketCouponList());
            if (!mapCoupon.isEmpty()) {
                jsonResult.custom("8", "礼包含有赠送卡卷的库存不足", log);
                jsonResult.data = mapCoupon;
                return;
            }

            Map<String, Map<Long, String>> mapProduct = giftPacketHelper.checkProduct(masterProduct, giftPacketDto.getMasterPacketProduct(), giftPacketDto.getCollocationPacketProductList());

            if (!mapProduct.get("quantity").isEmpty()) {
                jsonResult.custom("7", "礼包含有产品的库存不足", log);
                jsonResult.data = mapProduct.get("quantity");
                return;
            }
            if (!mapProduct.get("mapStatus").isEmpty()) {
                jsonResult.custom("9", "礼包含有产品不处于出售中", log);
                jsonResult.data = mapProduct.get("mapStatus");
                return;
            }

            //判断是否从我要销售接口进来
            MarketMerchantGiftPacketSales giftPacketSales = new MarketMerchantGiftPacketSales();
            List<MarketMerchantGiftPacketSales> merchantGiftPacketSales = marketMerchantGiftPacketSalesRepository.findByPacketIdAndSupplierMallIdAndSupplierMerchantIdAndDistributorMallIdAndDistributorMerchantIdAndDistributorStatus(giftPacketDto.getId(), merchantGiftPacket.getMallId(), merchantGiftPacket.getMerchantId(), userInfoDto.mall.getId(), userInfoDto.merchant.getId(), MarketMerchantProductSalesStatus.REFUSE);
            if (merchantGiftPacketSales.size() == 0){
                jsonResult.remind("发布失败!",log);
                return;
            }else {
                giftPacketSales = merchantGiftPacketSales.get(0);
                giftPacketSales.setDistributorStatus(MarketMerchantProductSalesStatus.PASS);
                giftPacketSales.setSupplierStatus(MarketMerchantProductSalesStatus.PASS);
                giftPacketSales.setIsDelete(Whether.NO);

            }

            MerchantGiftPacket giftPacket = new MerchantGiftPacket();
            giftPacket.setName(giftPacketDto.getName());
            giftPacket.setBasePrice(new BigDecimal(giftPacketDto.getBasePrice()));
            giftPacket.setCoverUrl(giftPacketDto.getCoverUrl());
            giftPacket.setDateDisabled(giftPacketDto.getDateDisabled());
            giftPacket.setDateEnabled(giftPacketDto.getDateEnabled());
            giftPacket.setIntro(giftPacketDto.getIntro());
            giftPacket.setMallId(userInfoDto.mall.getId());
            giftPacket.setMerchantId(userInfoDto.merchant.getId());
            giftPacket.setRecommend(giftPacketDto.getRecommend());
            giftPacket.setShareFee(new BigDecimal(giftPacketDto.getShareFee()));
            giftPacket.setSellPrice(new BigDecimal(giftPacketDto.getSellPrice()));
            giftPacket.setStatus(GiftPacketStatus.valueOf(giftPacketDto.getStatus()));//礼包状态
            giftPacket.setMerchantName(userInfoDto.merchant.getName());
            giftPacket.setMarketId(giftPacketDto.getId());
            giftPacket.setResellFee(new BigDecimal(mapProduct.get("resellFee").get(0L).toString()));
            final MerchantGiftPacket finalGiftPacket = merchantGiftPacketRepository.save(giftPacket);

            marketMerchantGiftPacketSalesRepository.save(giftPacketSales);

            final Long supplierMerchantId = userInfoDto.merchant.getId();
            //添加合作关系
            MarketMerchantCooperation marketMerchantCooperation = null;
            Long masterSupplierMerchantId = giftPacketDto.getMasterPacketProduct().getMerchantId();
            if (giftPacketDto.getMasterPacketProduct().getMarketId() != null) {
                masterSupplierMerchantId = giftPacketDto.getMasterPacketProduct().getMarketMerchantId();
            }
            marketMerchantCooperation = marketMerchantCooperationRepository.findBySupplierMerchantIdAndDistributorMerchantIdAndStatusNot(masterSupplierMerchantId, userInfoDto.merchant.getId(), MarketMerchantCooperationStatus.REFUSE);
            if (marketMerchantCooperation == null  && !Objects.equals(masterSupplierMerchantId, supplierMerchantId)) {
                giftPacketHelper.saveMarketMerchantCooperation(userInfoDto, masterSupplierMerchantId);
            }

            if (giftPacketDto.getCollocationPacketProductList() != null && giftPacketDto.getCollocationPacketProductList().size() > 0) {
                for (MerchantGiftPacketProductDto ignored : giftPacketDto.getCollocationPacketProductList()) {
                    Long collocationSupplierMerchantId = ignored.getMerchantId();
                    if (ignored.getMarketMerchantId() != null) {
                        collocationSupplierMerchantId = ignored.getMarketMerchantId();
                    }
//                    log.info("======================>");
                    marketMerchantCooperation = marketMerchantCooperationRepository.findBySupplierMerchantIdAndDistributorMerchantIdAndStatusNot(collocationSupplierMerchantId, userInfoDto.merchant.getId(), MarketMerchantCooperationStatus.REFUSE);
                    if (!Objects.equals(masterSupplierMerchantId, collocationSupplierMerchantId) && marketMerchantCooperation == null) {
                        giftPacketHelper.saveMarketMerchantCooperation(userInfoDto, collocationSupplierMerchantId);
                    }
                }
            }

            //判断产品是否是自己产品(自己分销产品)    主产品
            Product selfProduct = giftPacketHelper.isSelfProduct(userInfoDto, giftPacketDto.getMasterPacketProduct());
            if (selfProduct != null) {
                giftPacketDto.getMasterPacketProduct().setProductId(selfProduct.getId());
                giftPacketDto.getMasterPacketProduct().setMerchantId(selfProduct.getMerchantId());
                if (selfProduct.getMarketId() != null) {
                    giftPacketDto.getMasterPacketProduct().setMarketId(selfProduct.getMarketId());
                    giftPacketDto.getMasterPacketProduct().setMarketMerchantId(selfProduct.getMarketMerchantId());
                }
            }

            //产品设置
            //主产品
            giftPacketHelper.saveMerchantGiftPacketProduct(finalGiftPacket.getId(), giftPacketDto.getMasterPacketProduct(), GiftPacketProductType.MASTER);
            //搭配产品
            if (giftPacketDto.getCollocationPacketProductList() != null && giftPacketDto.getCollocationPacketProductList().size() > 0) {
                for (MerchantGiftPacketProductDto productStr : giftPacketDto.getCollocationPacketProductList()) {
                    //判断产品是否是自己产品(自己分销产品)    搭配产品
                    selfProduct = giftPacketHelper.isSelfProduct(userInfoDto, productStr);
                    if (selfProduct != null) {
                        productStr.setMerchantId(selfProduct.getMerchantId());
                        productStr.setProductId(selfProduct.getId());
                        if (selfProduct.getMarketId() != null) {
                            productStr.setMarketId(selfProduct.getMarketId());
                            productStr.setMarketMerchantId(selfProduct.getMarketMerchantId());
                        }
                    }
                    giftPacketHelper.saveMerchantGiftPacketProduct(finalGiftPacket.getId(), productStr, GiftPacketProductType.COLLOCATION);
                }
            }
            //卡卷设置
            if (giftPacketDto.getMerchantPacketCouponList() != null && giftPacketDto.getMerchantPacketCouponList().size() > 0) {
                for (MerchantGiftPacketCouponDto couponStr : giftPacketDto.getMerchantPacketCouponList()) {
                    giftPacketHelper.saveMerchantGiftPacketCoupon(finalGiftPacket.getId(), couponStr);
                }
            }


        };
        return doing.go(request, log);
    }
}
